package com.chenjun.common.util.aes;
/*package com.candowin.common.util.aes;

import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;

import com.rt.BASE64Decoder;
import com.rt.BASE64Encoder;

public class AES {
	
	 // 加密
   public static String Encrypt(String sSrc, String sKey) throws Exception {
     
       byte[] raw = sKey.getBytes("utf-8");
       SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");
       Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");//"算法/模式/补码方式"
       cipher.init(Cipher.ENCRYPT_MODE, skeySpec);
       byte[] encrypted = cipher.doFinal(sSrc.getBytes("utf-8"));
       return new BASE64Encoder().encodeBuffer(encrypted);//此处使用BASE64做转码功能，同时能起到2次加密的作用。
   }
   
   // 加密
   public static String encryptNoPadding(String sSrc, String sKey) throws Exception {
     
       byte[] raw = sKey.getBytes("utf-8");
       SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");
       Cipher cipher = Cipher.getInstance("AES/ECB/NoPadding");//"算法/模式/补码方式"
       cipher.init(Cipher.ENCRYPT_MODE, skeySpec);
       byte[] encrypted = cipher.doFinal(sSrc.getBytes("utf-8"));
       return new BASE64Encoder().encodeBuffer(encrypted);//此处使用BASE64做转码功能，同时能起到2次加密的作用。
   }
   
   // 加密
   public static String Encrypt(String sSrc) throws Exception {
      
	  String strkey = "cxc1989080811068";
      return Encrypt(sSrc,strkey);
   }
   
   // 加密
   public static String encryptNoPadding(String sSrc) throws Exception {
      
	  String strkey = "cxc1989080811068";
      return encryptNoPadding(sSrc,strkey);
   }

   // 解密
   public static String Decrypt(String sSrc, String sKey) throws Exception {
       try {
           
    	   sSrc = sSrc.replaceAll(" ", "\\+");
           byte[] raw = sKey.getBytes("utf-8");
           SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");
           Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
           cipher.init(Cipher.DECRYPT_MODE, skeySpec);
           byte[] encrypted1 = new BASE64Decoder().decodeBuffer(sSrc);//先用base64解密
           try {
               byte[] original = cipher.doFinal(encrypted1);
               String originalString = new String(original,"utf-8");
               return originalString;
           } catch (Exception e) {
               System.out.println(e.toString());
               return null;
           }
       } catch (Exception ex) {
           System.out.println(ex.toString());
           return null;
       }
   }
   
   // 解密
   public static String decryptNoPadding(String sSrc, String sKey) throws Exception {
       try {
           
    	   sSrc = sSrc.replaceAll(" ", "\\+");
           byte[] raw = sKey.getBytes("utf-8");
           SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");
           Cipher cipher = Cipher.getInstance("AES/ECB/NoPadding");
           cipher.init(Cipher.DECRYPT_MODE, skeySpec);
           byte[] encrypted1 = new BASE64Decoder().decodeBuffer(sSrc);//先用base64解密
           try {
               byte[] original = cipher.doFinal(encrypted1);
               String originalString = new String(original,"utf-8");
               return originalString;
           } catch (Exception e) {
               System.out.println(e.toString());
               return null;
           }
       } catch (Exception ex) {
           System.out.println(ex.toString());
           return null;
       }
   }
   
   public static String Decrypt(String sSrc) throws Exception
   {
	   String strkey = "cxc1989080811068";
	   return Decrypt(sSrc,strkey);
   }
   
   public static String decryptNoPadding(String sSrc) throws Exception
   {
	   String strkey = "cxc1989080811068";
	   return Decrypt(sSrc,strkey);
   }
   
   public static byte[] Encrypt(byte[] buffer, String sKey) throws Exception {
	     
       byte[] raw = sKey.getBytes("utf-8");
       SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");
       Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");//"算法/模式/补码方式"
       cipher.init(Cipher.ENCRYPT_MODE, skeySpec);
       byte[] encrypted = cipher.doFinal(buffer);
       return encrypted;
   }
   
   public static byte[] encryptNoPadding(byte[] buffer, String sKey) throws Exception {
	     
       byte[] raw = sKey.getBytes("utf-8");
       SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");
       Cipher cipher = Cipher.getInstance("AES/ECB/NoPadding");//"算法/模式/补码方式"
       cipher.init(Cipher.ENCRYPT_MODE, skeySpec);
       byte[] encrypted = cipher.doFinal(buffer);
       return encrypted;
   }
   
	 // 加密
   public static byte[] Encrypt(byte[] buffer) throws Exception {
      
	  String strkey = "cxc1989080811068";
      return Encrypt(buffer,strkey);
   }
   
	 // 加密
   public static byte[] encryptNoPadding(byte[] buffer) throws Exception {
      
	  String strkey = "cxc1989080811068";
      return encryptNoPadding(buffer,strkey);
   }
   
   public static byte[] Decrypt(byte[] buffer,String strKey) throws Exception
   {
	   byte[] raw = strKey.getBytes("utf-8");
       SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");
       Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
       cipher.init(Cipher.DECRYPT_MODE, skeySpec);
       try {
           byte[] original = cipher.doFinal(buffer);
           return original;
       } catch (Exception e) {
           System.out.println(e.toString());
           return null;
       }   
   }
   
   public static byte[] decryptNoPadding(byte[] buffer,String strKey) throws Exception
   {
	   byte[] raw = strKey.getBytes("utf-8");
       SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");
       Cipher cipher = Cipher.getInstance("AES/ECB/NoPadding");
       cipher.init(Cipher.DECRYPT_MODE, skeySpec);
       try {
           byte[] original = cipher.doFinal(buffer);
           return original;
       } catch (Exception e) {
           System.out.println(e.toString());
           return null;
       }   
   }
   
   public static byte[] Decrypt(byte[] buffer) throws Exception
   {
	   String strkey = "cxc1989080811068";
	   return Decrypt(buffer,strkey);
   }
   
   public static byte[] decryptNoPadding(byte[] buffer) throws Exception
   {
	   String strkey = "cxc1989080811068";
	   return decryptNoPadding(buffer,strkey);
   }
   
   public static String EncryptBuffer(byte[] buffer)
   {
 	 return new BASE64Encoder().encodeBuffer(buffer);
   }
   
   public static byte[] DecryptString(String strBuffer)
   {
 	 try {
 		return new BASE64Decoder().decodeBuffer(strBuffer);
 	 } catch (Exception ex) {
 		// TODO Auto-generated catch block
 		ex.printStackTrace();
 	 }
 	return null;
   }
  
   public static void main(String[] args){
	   try {
		System.out.println(Encrypt("wangwanzhou"));
	} catch (Exception e) {
		e.printStackTrace();
	}
   }

}*/